package com.example.xd.model_video.clipvideo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.xd.model_video.R;
import com.example.xd.model_video.VideoActivity;

public class VideoEditActivity extends AppCompatActivity {

    private VideoView videoView;
    String url1 = "/storage/emulated/0/AzRecorderFree/2017_07_07_15_24_06.mp4";
    String url2 = "/storage/emulated/0/AzRecorderFree/2017_07_07_18_52_35.mp4";
    String url3 = "/storage/emulated/0/电影/1558593082556.mp4";
    String url5 = "/storage/emulated/0/DCIM/crop_1559011435029.mp4";
    private ClipView mClip_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_edit);
        videoView = findViewById(R.id.uVideoView);
        mClip_view = findViewById(R.id.clip_view);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipVideoUtil.getInstance().complexVideo(url5, new ComplexListener() {
                    @Override
                    public void noNeedComplex(String path) {
                        Log.i("xd-----------", "无需合成的路径--" + path);
                        Intent intent = new Intent(VideoEditActivity.this, VideoActivity.class);
                        intent.putExtra("path", path);
                        startActivity(intent);

                    }

                    @Override
                    public void complexSuccess(String path) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Log.i("xd-----------", "合成成功的路径--" + path);
                                Intent intent = new Intent(VideoEditActivity.this, VideoActivity.class);
                                intent.putExtra("path", path);
                                startActivity(intent);
                            }
                        });

                    }

                    @Override
                    public void complexFail() {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(VideoEditActivity.this, "合成失败", Toast.LENGTH_SHORT).show();
                            }
                        });

                    }

                    @Override
                    public void complexing(float progress) {
                        Log.i("xd-----", "progress----" + progress);
                    }
                });
            }
        });

        ClipVideoUtil.getInstance().initvideo(this, mClip_view, videoView, url5);
    }


    @Override
    protected void onPause() {
        super.onPause();
        if (videoView != null && videoView.isPlaying()) {
            ClipVideoUtil.getInstance().onPause(videoView);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (videoView != null) {
            ClipVideoUtil.getInstance().onResume(videoView);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ClipVideoUtil.getInstance().destory();
    }
}
